package com.scoy.honeymei.activity.me;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.lzy.okgo.model.HttpParams;
import com.scoy.honeymei.R;
import com.scoy.honeymei.adapter.CouponListAdapter;
import com.scoy.honeymei.adapter.VipHisAdapter;
import com.scoy.honeymei.base.BaseActivity;
import com.scoy.honeymei.bean.CouponBean;
import com.scoy.honeymei.bean.FilmVipBean;
import com.scoy.honeymei.dialog.TicketSendDialog;
import com.scoy.honeymei.http.HpCallback;
import com.scoy.honeymei.http.HpGo;
import com.scoy.honeymei.url.MeConstant;
import com.scoy.honeymei.url.MyUrl;
import com.scoy.honeymei.utils.GlideImgUtil;
import com.scoy.honeymei.utils.MyUtil;
import com.scoy.honeymei.utils.SPHelper;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * @ClassName: MeVipActivity$
 * @Description: 我的观影会员
 * @Author: GaoZhan
 * @CreateDate: 2019/9/4/0004$ 上午 11:29$
 * @UpdateUser: 更新者
 * @UpdateDate: 2019/9/4/0004$ 上午 11:29$
 * @UpdateRemark: 更新内容
 */
public class MeVipActivity extends BaseActivity {

    @BindView(R.id.back_iv)
    ImageView backIv;
    @BindView(R.id.title_tv)
    TextView titleTv;
    @BindView(R.id.sign_tv)
    TextView signTv;
    @BindView(R.id.title_llt)
    LinearLayout titleLlt;
    @BindView(R.id.mv_viewnumdd_tv)
    TextView mvViewnumddTv;
    @BindView(R.id.mv_numbers0_tv)
    TextView mvNumbers0Tv;
    @BindView(R.id.mv_torecord_tv)
    TextView mvTorecordTv;
    @BindView(R.id.mv_leftadd_tv)
    TextView mvLeftaddTv;
    @BindView(R.id.mv_numbers1_tv)
    TextView mvNumbers1Tv;
    @BindView(R.id.mv_line)
    View mvLine;
    @BindView(R.id.mv_vippriceadd_tv)
    TextView mvVippriceaddTv;
    @BindView(R.id.mv_price_tv)
    TextView mvPriceTv;
    @BindView(R.id.mv_qr_iv)
    ImageView mvQrIv;

    @BindView(R.id.mv_senddo_tv)
    TextView mvSenddoTv;
    private MeVipActivity mContext;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_mevip);
        ButterKnife.bind(this);
        mContext = MeVipActivity.this;

        initNormal();

        httpMeCoupon();

    }

    @Override
    public void initNormal() {
        titleTv.setText(R.string.mevip);

        MyUtil.setStatusBar(mContext, getWindow(), true, R.color.colorWhite);
        titleLlt.setPadding(0, MyUtil.getStatusBarHeight(mContext), 0, 0);

    }


    @OnClick({R.id.back_iv, R.id.mv_torecord_tv, R.id.mv_senddo_tv})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.back_iv:
                finish();
                break;
            case R.id.mv_torecord_tv:
                startActivity(new Intent(mContext, VipHisActivity.class));
                break;
            case R.id.mv_senddo_tv:
                TicketSendDialog.newInstance().setOnDialogBack(() -> {
                    httpMeCoupon();
                }).show(getSupportFragmentManager(), "");
                break;
        }
    }

    private void httpMeCoupon() {
        HttpParams params = new HttpParams();
        params.put("uid", SPHelper.getString(MeConstant.UID, ""));
        HpGo.newInstance().HttpGo(this, MyUrl.MOVIE_VIP_ME, params, new HpCallback() {
            @Override
            public void onSuccess(String o) {
                FilmVipBean filmVipBean = new Gson().fromJson(o, FilmVipBean.class);
                FilmVipBean.UserBean user = filmVipBean.getUser();
                String erweima = filmVipBean.getErweima();
                if (erweima == null || "".equals(erweima)) {
                    mvQrIv.setVisibility(View.GONE);
                } else {
                    GlideImgUtil.glidePic(mContext, erweima, mvQrIv);
                }
                mvNumbers0Tv.setText(user.getMovie_total() + "次");
                mvNumbers1Tv.setText(user.getMovie_count() + "次");

                mvVippriceaddTv.setVisibility(View.GONE);
            }

            @Override
            public void onFailed(String code, String msg, String o) {
                MyUtil.mytoast(mContext, code + "," + msg);
            }

            @Override
            public void onError(int code, String errorMsg) {
                MyUtil.mytoast(mContext, errorMsg);
            }
        });

    }
}
